/**
 * 保存用户token
 * @type {null}
 */
var token = null

/**
 * 登录操作逻辑
 * */
$("#user_login").click(function () {
    var url = "/user/login"
    var userName = $("#userName").val()
    var userPassword = $("#userPassword").val()
    if (!userName) {
        alert("账号必填")
        return;
    }
    if (!userPassword) {
        alert("密码不能为空")
        return;
    }
    var user = {
        "userName": userName,
        "userPassword": userPassword
    }
    var json = JSON.stringify(user)
    //发送post请求验证登录
    $.ajax({
        url: url,
        type: 'post',
        dataType: 'json',
        data: json,
        contentType: 'application/json',
        success: function (data) {
            alert(data.message)
            var token = data.token
            $.cookie('token', token, {expires:1, path: '/'})
            $(window).attr('location', '/admin/index?token=' + token)
        },
        error: function () {
            alert("失败，重试")
        }
    })
})

